<?php
/* 
 * ********* CVS HEADER ********* 
 * 
 * $RCSfile: lostlogin.php,v $ 
 * $Date: 2005/08/29 15:34:02 $ 
 * $Revision: 1.2 $ 
 * 
 * ********* CVS HEADER ********* 
 */
if($action=="process"){
	$query = "SELECT * FROM utilisateur WHERE login='$id' AND email='$email'";
	$result=rportalrequete($query) or rportalerreur("Vos coordonnees sont inexates.","?op=lostlogin");
	if($user = rportalligne($result)){
		require_once(get_path_module("password.password"));
		$pwd = getRandomPassword(8);
		$L_pwd = $pwd;
		$pwd=md5("$L_pwd");
		$groupdefseq = $rportalparams->get_value("RPORTAL","groupe.sequenceur");
		$query ="UPDATE utilisateur SET password='$pwd',id_groupe='$groupdefseq' WHERE login='$id' AND email='$email'";
		$res=@rportalrequete($query) or rportalerreur ($query,"?op=");
		$argid=rportallastid($res);
		$seq=$rportalparams->get_value("RPORTAL","sequence.password");
		$query="SELECT id FROM sequence_ordre WHERE id_sequence='$seq' ORDER BY id";
		$result2=rportalrequete($query) or rportalerreur ($query,"?op=");
		$etape=-1;
		if($row2=rportalligne($result2)) {
			$etape=$row2["id"];
		}
		$query ="INSERT INTO sequence_status (login,id_groupe,etape,id_sequence)";
		$query.=" VALUES ('{$user['login']}','{$user['id_groupe']}','$etape','$seq')";
		$result=rportalrequete($query) or rportalerreur ($query,"?op=");
		
		require_once(get_path_module("email.emailtype"));
		$email = new emailtype($rportalparams->get_value("RPORTAL","email.compte.nouveau.password"));
		$email->setFrom($rportalparams->get_value("SITE","webmaster.nom"),$rportalparams->get_value("SITE","webmaster.email"));
		$email->setTo($user['email'],$user['login'],$user['nom'],$user['prenom'],$L_pwd);
		
		if(trim($rportalparams->get_value("RPORTAL","email.actif"))=="yes" && $user['email']!='')
		{
			//echo nl2br($email->getMessage());
			$email->sendEmail();
			rportalmessage("Un nouveau mot de passe vous a ete envoye a votre adresse email.","?op=");
		}else{
			rportalerreur("Cette fonctionnalite n'est pas activee. [lostlogin]","?op=");			
		}
	}else{
		rportalerreur("Vos coordonnees sont inexates.","?op=lostlogin");
	}
}
$L_base_env = get_env_path();
require_once("module/TPLN/TPLN.php"); 
$TPLN = new TPLN; 
$TPLN->Open($op_basepath."tpl/lostlogin.html"); 
$TPLN->IncludeFile("header",$L_base_env.$session['environnement']."/header.php"); 
$TPLN->IncludeFile("footer",$L_base_env.$session['environnement']."/footer.php");
$TPLN->Parse("login",$id);
$TPLN->Write();
?>